unit SelectGroup;

interface

uses
  Database,
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ExtCtrls, ColorGrd, Mask, Groups, DBCtrls;

type
  TFormSelectGroup = class(TForm)
    BtnOK: TBitBtn;
    BtnCancel: TBitBtn;
    Panel1: TPanel;
    Label1: TLabel;
    BtnGroups: TSpeedButton;
    EditGroup: TDBComboBox;
    procedure BtnCancelClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure BtnOKClick(Sender: TObject);
    procedure BtnGroupsClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    oldgroup, group: string;
  end;

var
  FormSelectGroup: TFormSelectGroup;

implementation
uses
   DBClient;

{$R *.DFM}

procedure TFormSelectGroup.FormCreate(Sender: TObject);
begin
  group:='';
end;

procedure TFormSelectGroup.BtnCancelClick(Sender: TObject);
begin
  close;
end;

procedure TFormSelectGroup.BtnOKClick(Sender: TObject);
begin
  if EditGroup.text = '' then begin
    messagedlg('You must select a group',mtinformation,[mbok],0);
    EditGroup.setfocus;
    exit;
  end;
  group:=EditGroup.text;
  close;
end;

procedure TFormSelectGroup.BtnGroupsClick(Sender: TObject);
var form: TFormGroups;
begin
  form:=TFormGroups.create(self);
  form.frommain:=false;
  form.showmodal;
  form.free;
  FormShow(nil);
end;

procedure TFormSelectGroup.FormShow(Sender: TObject);
var table: TClientDataset;
begin
  table:=TClientDataset.create(self);
  with table do begin
    cloneCursor(Datawell.TableGroups, false);
    active:=true;
    first;
    EditGroup.items.clear;
    while not EOF do begin
      if fieldbyname('FGroup').asstring <> oldgroup then begin
        EditGroup.items.add(fieldbyname('FGroup').asstring);
      end;
      next;
    end;
  end;
end;

end.

